home *** CD-ROM | disk | FTP | other *** search
- Path: news.win.tue.nl!not-for-mail
- From: exspectf@wsinis12.win.tue.nl (Richard Braeken)
- Newsgroups: comp.lang.c
- Subject: Serial port Sparc Station -> C program
- Date: 21 Feb 1996 17:30:25 +0100
- Organization: Eindhoven University of Technology, the Netherlands
- Message-ID: <4gfhb1$l3e@wsinis12.win.tue.nl>
- NNTP-Posting-Host: wsinis12.win.tue.nl
-
- Hello,
-
- I am working on a project for my university which has to do with a
- digital model railroad. Instead of using a control unit I use my Sparc
- Station, a serial port and a C program. To change the speed of the loc
- I have to send a number through this port. This works the way it
- should.
-
- However when I read from the port I have a problem. The program hangs. I
- think I have used a wrong set up, but after a day of reading the manuals
- I still have no idea what's wrong.
-
- I have attached the program to this posting. Is there anybody in this
- newsgroup who has some knowledge of serial ports of Sparc Stations.
- Your help is greatly appreciated.
-
- Thanks in advance,
-
- Richard
-
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <termios.h>
-
- int ttyfile;
- int errno;
-
- void initial()
- {
- struct termios bla;
- int flags;
-
- flags = O_RDWR | O_NDELAY;
- ttyfile = open("/dev/ttya", flags);
- if (ttyfile<0) {
- fprintf(stderr,"error\n");
- exit(1);
- }
- if (tcgetattr(ttyfile, &bla)) {
- fprintf(stderr,"error\n");
- exit(1);
- }
- bla.c_oflag = 0;
- bla.c_iflag = 0;
- bla.c_cflag = CS8 | CSTOPB | CLOCAL;
- if (cfsetospeed(&bla,B2400)) {
- fprintf(stderr,"error\n");
- exit(1);
- }
- if (cfsetispeed(&bla,B2400)) {
- fprintf(stderr,"error\n");
- exit(1);
- }
-
- if (tcsetattr(ttyfile, TCSANOW, &bla)) {
- fprintf(stderr,"error\n");
- exit(1);
- }
- }
-
-
- int main()
- {
- char inp;
- char outp;
-
-
- initial();
- inp = 193;
- if (write(ttyfile, &inp, 1) < 0) printf("Error writing\n");
- else printf("Ready writing\n");
- if (read(ttyfile, &outp,1) < 0) /* Here the program hangs */
- { printf("Error reading ");
- printf("%d\n", errno);
- }
- else printf("Ready reading\n");
- printf("Output :%s of %d of %o.\n", outp, outp, outp);
- close(ttyfile);
- }
-
- --
- Richard Braeken | Ura ni wa ura ga aru
- more info: | The reverse sight has a reverse side
- finger exspectf@win.tue.nl | (Japanese saying)
-